from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from common.Utils import BlogDriver
#测试博客编辑页面
class BlogEdit:
    url = ""
    driver = ""
    def __init__(self):
        #点击写博客跳转的url
        self.url = "http://8.137.19.140:9090/blog_edit.html"
        self.driver = BlogDriver.driver
        self.driver.get(self.url)

    #正常发布博客
    def EditSucTestByLogin(self):
#找到标题框，输入博客标题
        self.driver.find_element(By.CSS_SELECTOR, "#title").send_keys("自动化测试创建")
        wait = WebDriverWait(self.driver, 3)
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        BlogDriver.getScreeShot()
        #错误发布博客
    def EditFailTestByLogin(self):
        #无标题无内容直接发布
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        #异常登陆弹窗要添加等待，这样才能看到
        wait = WebDriverWait(self.driver, 3)
        wait.until(EC.alert_is_present())
        BlogDriver.getScreeShot()
        alert = self.driver.switch_to.alert
        # 确认
        alert.accept()

